\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{setspace}\usepackage[colorlinks=true,urlcolor=blue,linkcolor=black,citecolor=red]{hyperref}
\usepackage{url}
\begin{document}

\begin{titlepage}
\begin{center}

\vspace*{3in}

{\huge Pigasus}

{\it The Language Reference Manual}

\vspace*{0.5in}

COMS W4115

\today

\vfill

\end{center}

\begin{flushright}

{\bf Team Hogzilla}

{\it Project Manager:} John Zhang (jrz2106)

{\it System Architect:} Sharath Gururaj (sa2617)

{\it Language Guru:} Jordan Rupprecht (jjr2119)

{\it Verification and Validation Person:} Philip Tjimos (pmt2103)

{\it System Integrator:} Everyone

\end{flushright}
\end{titlepage}

\tableofcontents
\newpage

\section{Introduction}

We present here the reference manual for the Pigasus programming 
language. Pigasus is designed to facilitate the process of distributing executable binaries or scripts to multiple machines over an arbitrary network for parallel execution as well as easily providing the input to and retrieving the output from these concurrently running tasks.

\subsection{Objectives}

The main objective of Pigasus is to greatly simplify the process of establishing
network connections and quickly transmitting data between the \emph{host}, the
user's primary machine from which the Pigasus program is being run, and the
\emph{remote server} nodes, which are the machines in the network cluster running the individual tasks. With this goal in mind, Pigasus' language constructs will revolve around this, and other capabilities such as advanced data processing, mathematical functions will not be supported. However, Pigasus will also be able to closely interact with the shell, so that if the aforementioned capabilities are needed, the user is free to provide binaries or scripts (written in other languages) and ``plug them in'' to their Pigasus program.

\subsection{Types}

The Pigasus language will be typed. In addition to common types such as
\verb|int|, \verb|float|, \verb|string| which are present in many
general-purpose languages, Pigasus will also include types designed to
facilitate the act of establishing network connections and transmitting data
(i.e. \verb|file|). These types will be simplified so that users can quickly
specify remote servers and communicate with them.

\subsection{Compiled}

Pigasus is a compiled language. When source code is provided to the Pigasus
compiler, the compiler will translate the program into an intermediate
representation (namely, C++) which will then be compiled into native code using
a common C++ compiler such as G++.

\subsection{Imperative}

To reduce the learning curve for Pigasus, the language will be imperative and similar in structure to C/C++. 

\subsection{And Finally...}

Now that a brief overview of the main characteristics of the language has been provided, we can proceed to describe the language specification in detail. The features described in the following sections will be supported in our final implementation. The only exception to this is Section \ref{sec:future_work}, which lists language features which we may eventually add to Pigasus if time permits.

\section{Lexical Conventions}

There will be five kinds of tokens: identifiers, keywords, constants, expression operators and other separators. Whitespace must be used to separate tokens, but are otherwise inconsequential. An important note is that Pigasus is entirely case-sensitive. We will also follow the ``leftmost-longest'' policy for tokenization, whereby each token is the longest string of characters that can constitute a token.

\subsection{Comments}

Comments in Pigasus will follow the format similar to C++. Multiline comments are delimited by \verb|/*| and \verb|*/|. Single line comments begin with \verb|//| and are terminated by an end-of-line character. 

\subsection{Identifiers}

Identifiers are sequences of English alphabet letters, digits and the underscore character, but cannot begin with a digit. Therefore, identifiers will adhere to the following regular expression:
\begin{quote}\begin{verbatim}
[a-zA-Z_][a-zA-Z0-9_]*
\end{verbatim}\end{quote}

\subsection{Constants}

Pigasus will support the following types of constants.

\subsubsection{Numeric constants}
Numeric constants can be integer constants or float constants. The former would consist of a sequence of digits. The latter is a sequence of digits with a decimal point. Both types can optionally be prefixed by a \verb|+| or \verb|-|, which changes the sign.

\subsubsection{String constants}
String constants are sequences of characters delimited by quotation marks. We will use C-like character escaping to denote newlines, tabs, etc. Note however, that Pigasus does not explicitly support character as its own type. The following escaped characters will be supported.
\begin{itemize}
\item \verb|\n|: new lines.
\item \verb|\t|: tab character.
\item \verb|\\|: the backslash character.
\item \verb|\"|: the double quote.
\end{itemize}

\subsubsection{Boolean constants}
The only two possible boolean values are \verb|true| and \verb|false|.

\subsection{Keywords}

Many of the keywords used in Pigasus for general purpose instructions are adopted from C. The keywords are listed in Table \ref{tab:keywords}.

\begin{table}[ht]
\centering
\begin{tabular}{lp{0.5in}l}
General & & Pigasus-specific \\ \hline
\verb|int|		& & \verb|length| \\
\verb|float|	& & \verb|list| \\
\verb|string|	& & \verb|file| \\
\verb|bool|		& & \verb|push| \\
\verb|null|		& & \verb|wait| \\
\verb|return|	& & \verb|loadcsv| \\
\verb|break|	& & \verb|job| \\
\verb|continue|& & \verb|map| \\
\verb|if|		& & \verb|post| \\
\verb|else|		& & \verb|waitall| \\
\verb|for|		& & \verb|postall| \\
\verb|do|		& & \verb|print| \\
\verb|while| 	& & \verb|typeof| \\
\verb|true| 	& & \verb|connect| \\
\verb|false| 	& & \\
\verb|void|		& & \\
\end{tabular}	
\caption{Supported keywords.}
\label{tab:keywords}
\end{table}

\section{Conversions}

It is often the case that you way wish to apply an operator to operand(s) of types not usually supported by the operator. Pigasus requires that the programmer explicitly cast all values to the correct type before using them as an operand to an operator requiring that type. That is, there will be no automatic casting. To cast a value to a specific type, see the casting operator in Section \ref{sec:casting_operator}. The rules for conversions between types will be given here. Please beware of overflowing numerical values (i.e. integers and floats), as it will cause incorrect values to be returned. Please see Section \ref{sec:types} for details regarding the types.

\subsection{String and Integer}
\label{sec:stringandinteger}

To cast a string to an integer, the leftmost longest substring of the given string consisting of only digits (possibly led by a ``-'' symbol) will be returned as an integer. If the string does not contain a viable integer, then 0 will be returned. More specifically, this will be implemented using the C \verb|sscanf| function, that is, the conversion will be equivalent to the following C++ function:
\begin{quote}\begin{verbatim}
int StringToInteger(string str) {
  int x = 0;
  sscanf(str.c_str(), "%d", &x);
  return x;
}
\end{verbatim}\end{quote}

Casting a integer to a string is straightforward: the integer becomes a string consisting of the same digits and possibly the negative sign.

\subsection{String and Floating Point Number}

Given a string to cast to a float, the leftmost longest substring consisting of only digits, possibly led by a ``-'' symbol, consisting of a single decimal point, will be returned as a float. If the string does not contain a viable float, then 0.0 will be returned. The implementation will be similar to what is described in \ref{sec:stringandinteger}.

Casting from a float to a string is done as follows. The float will be converted to its string representation, including a possible negative sign and up to 10 decimal places.

\subsection{String and Boolean}
To cast a string to a boolean value, if the string is non-empty (i.e. length greater than 0), \verb|true| will be returned. Otherwise, \verb|false| will be returned.

For the reverse, if a boolean value is cast into a string, then the value becomes the string ``true'' if the boolean value is true, and ``false'' otherwise.

\subsection{String and File}

To specify a file in Pigasus, the string filename needs to be cast to a \verb|file| type. That is, consider the following Pigasus code:
\begin{quote}\begin{verbatim}
file f = (file)"test.txt";
\end{verbatim}\end{quote}
This means that the value of \verb|f| is the file \verb|test.txt| in the working directory.

If a file is cast to a string, then only the filename is returned. So, take \verb|f| from above, then consider the following Pigasus code:
\begin{quote}\begin{verbatim}
string s = (string)f;
\end{verbatim}\end{quote}
Then \verb|s| will contain the string ``test.txt''.

\subsection{Integer and Floating Point Number}
When an integer is cast to a float, Returns a float with the same numeric value as the integer.

For the reverse, the float will be rounded to the nearest integer.

\subsection{Integer to Boolean}
When casting an integer to a boolean value, if the integer is 0, then \verb|false| is returned. Otherwise, \verb|true| is returned.

Similarly, casting a boolean value \verb|true| to an integer returns 1. Otherwise, 0 is returned.

\subsection{Floating Point Number to Boolean}
When casting a float value of 0.0, then boolean \verb|false| will be returned. Otherwise, \verb|true| is returned.

The reverse is similar to that of converting booleans to integers, except a float 0.0 or 1.0 will be returned instead of 0 or 1 respectively.

The user is warned that this conversion can be dangerous. While 0.0 translates to a \verb|false| boolean, an incredibly small but still finite value (e.g.\ 0.000001) translates to a \verb|true| boolean. Users should instead test if a certain floating point value is within a certain threshold of 0.0 (i.e.\ test if $|float| < \epsilon$).

\section{Types}
\label{sec:types}

Pigasus supports 7 native types. They are as follows.

\subsection{Integers}
Declared as \verb|int|. These are 32-bit signed integers. Pigasus does not distinguish between signed and unsigned.

\subsection{Floating Point Numbers}
Declared as \verb|float|. These are 64-bit floating point numbers (equivalent to C/C++/Java \verb|double|).

\subsection{Strings}
Declared as \verb|string|. These are sequences of characters of arbitrary length.

\subsection{Booleans}
Declared as \verb|bool|. These hold a value of either \verb|true| or \verb|false|.

\subsection{Lists}
Declared as \verb|list|. Pigasus does not have arrays in the same sense as C/C++/Java. Instead, list structures are used, which an be a list of any mix of natively-supported Pigasus types. Therefore a single list can contain strings, integers, other lists, etc.

\subsection{Associated Arrays / Maps}
Declared as \verb|map|. These structures map a string to values of any Pigasus native type. Access time will be $O(\lg n)$ (they will be implemented as C++ maps).

\subsection{Files}
Declared as \verb|file|. Files point to a file in either the host or remote machine (depending on whether they are used inside a \emph{job} or not). Currently, Pigasus does not support file input/output, so it is impossible to manually create files (unless you use the shell via Pigasus) or to read from and write to files. Therefore, the main purpose of \verb|file| is to identify files to be sent across the network.

\section{Expressions}
Pigasus will have C-style expressions. An expression is a list of ``;'' delimited \emph{statements}. expressions have a value and can appear on the right hand side of an assignment. The precedence of operators is the same as that of C. \verb|+| and \verb|*| associate left to right, and \verb|*| has a higher precedence.

As in C, the order of evaluations of expressions in an argument list is undefined and the programmer should not rely on a particular order

\subsection{Primary Expressions}
%NOTE: really?
Primary expressions consist of function calls and group left to right.

\subsection{Constant}
Constants include string, float, integer, or boolean constants.

\subsection{Parenthesized expressions}
The value of a parenthesized expression, denoted by \verb|(expression)| is the same as the expression without the parentheses.
 
\subsection{Primary-expression[expression]}
In this type of expression, the square brackets denote subscripting. the \verb|Primary-expression| should evaluate to the type of \verb|list| or \verb|map|.

\subsection{Primary-expression(expression-list)}
This type of expressions primarily denote function calls. the
\verb|expression-list| is a (possibly empty) list of comma separated
\emph{parameters} to the function. The type of this expression is the same as
the type of the value returned by the function. For passing parameters, Pigasus
will employ the same policy as Java. That is, basic types such as
\verb|int, float, bool| will be passed by value. For 
\verb|string, list, map, file|, a reference will be passed.

\subsection{Unary Operators}

\subsubsection{- operator}
\begin{quote}\begin{verbatim}
-expression
\end{verbatim}\end{quote}

The result of this will be the negative of the expression of the same type, provided that the expresion is an \verb|int| or \verb|float|. If \verb|expression| is of a different type, the syntax is undefined (possibly syntax error).

\subsubsection{+ operator}
\begin{quote}\begin{verbatim}
+expression
\end{verbatim}\end{quote}

This operator returns the value of expression. This operator has no utility, except to maintain readability: some users may find it helpful to view positive numbers as explicitly stated.

\subsubsection{! operator}
\begin{quote}\begin{verbatim}
!expression
\end{verbatim}\end{quote}

The result will be the logical inverse of the expression, provided that the expression is of type \verb|bool|.

\subsection{Multiplicative Operators}

\subsubsection{* operator}
\begin{quote}\begin{verbatim}
expression * expression
\end{verbatim}\end{quote}

The binary operator \emph{*} represents multiplication, hence both expressions must be of type \verb|float| or \verb|int|. The result will always be the more precise type of the two expressions (i.e. if either type is \verb|float|, then the return type will be \verb|float|).

\subsubsection{/ operator}
\begin{quote}\begin{verbatim}
expression / expression
\end{verbatim}\end{quote}

The binary operator \emph{/} represents division, hence both expressions must be of type \verb|float| or \verb|int|. If the divisor is 0 (or 0.0 for floats), then this will cause a run-time (division-by-zero) error.

\subsection{The \% Operator}

The \% operator is a binary operator of the form \emph{expression \% expression}. If both expressions are numeric (i.e. \verb|float| or \verb|int|), then the operator is to be interpreted as a modulus operator. The result will be the modulus and will be of the same type as the more precise of the two expressions.

If the first expression is a string, then we use this operator as a \verb|sprintf()|-like operator (similar to the \% operator used in Python). That is, if the left expression is a string, then the right expression is to be a  list of variables which will be substituted into the string at run-time. For instance, given the following Pigasus string:
\begin{quote}\begin{verbatim}
"Hello %s, how are you %s?" % ["Alice", "Today"];
\end{verbatim}\end{quote}
This is equivalent to the string stored in the variable \verb|str| by the C function:
\begin{quote}\begin{verbatim}
sprintf(str, "Hello %s, how are you %s?", "Alice", "Today");
\end{verbatim}\end{quote}

\subsubsection{Format Specifiers}

Here is a list of the supported format specifiers (character strings
beginning with a \%). 
\begin{description}
\item[\%d] Decimal number. An optional parameter can be used in between the \%
symbol and ``dd'' to specify how the output may look. The same parameters as
those accepted by C's format specifier for integers (also ``\%d'') are accepted
by Pigasus.

\item[\%s] String. 

\item[\%f] Floating point number. Also accepts a parameter which can specify the
number of decimal places to show, etc. The same parameters as those accepted by
C's format specifier for doubles (``\%lf'') are accepted by Pigasus.
\end{description}

\subsection{Additive Operators}
The additive operators \verb|+| and \verb|-| are the same as C. They group left to right.

\subsubsection{expression+expression}
The result is the sum of the two expressions. In case of different types, the result is the type of the more precise operand-type. The \verb|+| operator is also defined for strings which has the meaning of concatenation. The result is a \emph{new} string object which is the concatenation of both the strings

\subsection{Relational Operators}
These are the usual relational operators:
\begin{itemize}
\item expression $<$ expression
\item expression $>$ expression
\item expression $>=$ expression
\item expression $<=$ expression
\end{itemize}

The value of the expression is the boolean value of the relational operator applied. We use the standard notions as used in C, i.e.\ we return \verb|true| if the mathematical evaluation is a true statement, and \verb|false| otherwise.

\subsection{Casting expressions}
\label{sec:casting_operator}
These are of the form:
\begin{quote}\begin{verbatim}
(type) expression
\end{verbatim}\end{quote}
\verb|type| refers to a datatype, such as \verb|int|, \verb|string|,
\verb|file|, etc. \verb|expression| refers to some expression that will be one
type that one wants in a different type. For example:
\begin{quote}\begin{verbatim}
(float)5 / (float)2 = 2.5
\end{verbatim}\end{quote}
Even though \verb|5 / 2 = 2|. 

\subsection{The Type-Of Expression}
These are of the form:
\begin{quote}\begin{verbatim}
typeof expression
\end{verbatim}\end{quote}
This returns the type of \verb|expression| as a string: ``int'', ``string'', ``float'', ``bool'', ``file'', ``list'', ``map''.

\subsection{The Length Expression}
These are of the form:
\begin{quote}\begin{verbatim}
length expression;
\end{verbatim}\end{quote}
Where \verb|expression| must evaluate to a string, list or map. For a string, the \verb|length| expression returns the number of characters in the string as an integer. For a list or map, it returns the number of items as an integer. 

\subsection{The Load-CSV Expression}
These are of the form 
\begin{quote}\begin{verbatim}
loadcsv string-expression;
\end{verbatim}\end{quote}
Where \verb|string-expression| is an expression that evaluates to a string. The string is expected to be the location (i.e. path and filename) of a CSV file which contains data regarding the specification of servers. The \verb|loadcsv| expression returns a list of maps which conform to the format needed by the \verb|connect| statement.

\section{Declarations}
Declarations are used within function definitions to specify how Pigasus will interpret each identifier.
\begin{quote}\begin{verbatim}
type_specifier init_declarator_list ';'
\end{verbatim}\end{quote}

This is the syntax used to declare variables. The syntax is identical to C.

\begin{quote}\begin{verbatim}
init_declarator_list
  : init_declarator
  | init_declarator_list ',' init_declarator
  ;
\end{verbatim}\end{quote}

This syntax shows how to declare one or more variables in a statement. For
example, \verb|int a;| is allowed, as is \verb|int a,b,c;|. We now describe the
details of which types of variables can be defined.

\subsection {Type specifiers}

Type specifiers define the type of the identifier being declared. Each identifier \emph{must} be declared before its first use.
\begin{itemize}

\item \verb|int|
\item \verb|float|
\item \verb|string|
\item \verb|bool|
\item \verb|list|
\item \verb|file|
\item \verb|map|

\end{itemize}

\subsection {Declarators and Declarator-lists}

A declarator-list is a comma-separated sequence of (possibly initialized) declaration of variables.
These have the following syntax 

\begin{quote}\begin{verbatim}
init_declarator_list:
         declarator
         declarator , init_declarator_list
\end{verbatim}\end{quote}

\subsection{Declarators}
Declarators have the syntax:

\begin{quote}\begin{verbatim}
declarator:
       identifier
\end{verbatim}\end{quote}

When a declarator appears in an expression, it yields an object of the indicated type named by its identifier. Each declarator can contain only one identifier; it is this identifier that is declared.

\subsection{General Type Declarations}

Common types \verb|string, int, float, bool| are declared the same way it is
done in C++. That is, they can be declared as follows:
\begin{quote}\begin{verbatim}
string a = "hello";
int b = -10;
int c;
float d = -5.0;
bool e = (true || false), f = true;
\end{verbatim}\end{quote}

\subsection {List Declarations}

A new list can be created with the following code:
\begin{quote}\begin{verbatim}
list my_list = ["C", "Java"];
\end{verbatim}\end{quote}
Lists are special in the sense that they can hold data of any type. The given
example declares a list \verb|my_list| of length 2 containing the strings
\verb|"C"| and \verb|"Java"|.

\subsection {File Declarations}

Files in languages like C and C++ are usually declared using file pointers and
opening a file. However, Pigasus does not support file I/O and therefore does
not give users the option to open the file. The ability to specify files is only
needed to identify them for transmission over the network.

A \verb|file| object is declared by casting a string to a file. The main
difference is that declaring a file object does not create any file. Since the
primary role of files in Pigasus is just as objects to be sent across the
network, the only operation supported for files is typecasting a string
(containing the file name) into a file. This step is necessary for Pigasus to be
able to send files across the network.

For instance, files are declared as follows:
\begin{quote}\begin{verbatim}
file f = (file)"helloworld.txt";
\end{verbatim}\end{quote}

\subsection {Job Declarations}

A job declaration has the following form:
\begin{quote}\begin{verbatim}
job_definition
  : job name '(' parameter_declaration ')' compound_statement
  ;
\end{verbatim}\end{quote}

For example, here is a sample Job declaration:
\begin{quote}\begin{verbatim}
job RunHello(list inputs) { 
  @{"./hello"};
}
\end{verbatim}\end{quote}
Job definitions can appear wherever a function definition can appear. Thus a Pigasus translation unit consists of function declarations and job declarations. 
 
\subsection {Map Declarations}
Maps are declared in the same manner as lists. The difference is in the initialization part, where we specify the key value pairs in the initial map.
Here is the syntax:

\begin{quote}\begin{verbatim}
map my_map = ["teamname" => "hogzilla", "compiler" => "Pigasus"]
\end{verbatim}\end{quote}
Note the use of the \verb|=>| operator to map a key to a value.

To associate a new key to a value, simply assign the value to the key as
follows. For instance:
\begin{quote}\begin{verbatim}
my_map["jordan"] = "iscool";
\end{verbatim}\end{quote}

\section{Statements}
Statements resemble C statements with all the usual constucts for compound statements like looping and conditional statements

\subsection{Expression Statement}
Most statements are just semicolon delimited expressions 
\begin{quote}\begin{verbatim}
expression;
\end{verbatim}\end{quote}

\subsection{Compound Statements}
These can be several statements where a single statement is expected 
\begin{quote}\begin{verbatim}
compound-statement:
               {statement-list}
statement-list:
               statement
               statement statement-list
\end{verbatim}\end{quote}

\subsection{Push Statements}
This is a Pigasus special statement. This is of the form
\begin{quote}\begin{verbatim}
push job-expression, file-expression, input-expression, 
     output-expression 
\end{verbatim}\end{quote}

This statement is the primary way in which programmers can push jobs to servers. \verb|job-expression| is an expression which evaluates to a Job object, \verb|file-expression| is an expression evaluating to a list containing binary executables that need to be sent over to the remote machine to be executed. \verb|input-expression| is a list of objects (like strings or file) which needs to be sent as inputs to the program. \verb|output-expression| is an expression which evaluates to a list to which all the output files generated by the program is copied

\subsection{Wait Statements}
These statements are used to create a blocking wait over a Pigasus distributed Job. Execution is suspended till the appropriate job is completed on the server and results are available. The following are the types of main

\subsubsection{Single Wait Statements}
These are of the form 
\begin{quote}\begin{verbatim}
wait id;
\end{verbatim}\end{quote}

Here \verb|id| is the integer id returned by the \verb|push| statements. Execution is suspended until the job represented by \verb|id| is completed.

\subsubsection{Wait-All Statements}

This is of the form 
\begin{quote}\begin{verbatim}
waitall;
\end{verbatim}\end{quote}

The effect of this statement is to suspend execution of the Pigasus program until \emph{all} the jobs sent out via \verb|push| are completed

\subsection{Post statement}
Similar to the \verb|wait| statements, these are of two flavors:

\subsubsection{Single Post Statements}
These are of the form 
\begin{quote}\begin{verbatim}
post id statement
\end{verbatim}\end{quote}

The main difference between \verb|wait| and \verb|post| is that \verb|post| is not blocking while \verb|wait| is blocking. This means that execution will continue beyond the code blocks in a normal way. The main function might end, but the Pigasus program will not terminate. Once the jobs waited on by \verb|post| is completed, \verb|statement| is executed asysnchronously.

\subsubsection{Post-All Statements}
These are of the form 
\begin{quote}\begin{verbatim}
postall statement
\end{verbatim}\end{quote}

The effect of this statement is to suspend execution until \emph{all} the jobs has completely executed. On this event, \verb|statement| is executed

\subsection{@ Statements}
These have the form:
\begin{quote}\begin{verbatim}
@{ expression };
\end{verbatim}\end{quote}
Where \verb|expression| must evaluate to a string.

The \verb|expression| is a string containing a shell command. This statement is
meant to allow the user quick access to the system. Note that if the @ statement
is used by the \verb|main| function, then the shell command will be executed on
the host. If the @ statement is used within a \verb|job|, then the shell command
will be executed remotely. This is true even if the @ statement is contained
within a function. That is, suppose function \verb|f()| contains an @ statement.
Then if a job calls \verb|f()|, the statement will be executed remotely. If
\verb|main| calls \verb|f()|, then the statement will be executed on the host.

\subsection{Conditional Statements}
These are the \verb|if-else| statements:
\begin{quote}\begin{verbatim}
if ( expression ) statement
if ( expression ) statement else statement
\end{verbatim}\end{quote}
As usual \verb|expression| is evaluated and if it is non-zero, the corresponding statement is executed. If the \verb|expression| is zero and an \verb|else| is provided, it will be executed. each \verb|else| is matched to the last \verb|if| which is unmatched

\subsection{While Statements}
These have the form:
\begin{quote}\begin{verbatim}while ( expression ) statement\end{verbatim}\end{quote}
The \verb|statement| is executed repeatedly as long \verb|expression| is non-zero. In particular, if \verb|expression| is zero on the outset, \verb|statement| is never executed

\subsection{Do-While Statements}
The \verb|do-while| statements have the following form:
\begin{quote}\begin{verbatim}
do statement while ( expression ) ;
\end{verbatim}\end{quote}
As in the case of a \verb|while| statement, \verb|statement| is executed repeatedly as long as \verb|expression| evaluates to a non-zero value, however, the main difference is that in this construct, \\ \verb|statement| is executed at least once, this means that the test takes place \emph{after} each execution of the \verb|statement| 
\subsection{For Statement}
\verb|for| statements have the following form
\begin{quote}
\begin{verbatim}
for ( optional-init-expr ; optional-cond-expr ; optional-post-expr )
  statement
\end{verbatim}\end{quote}

The for loop is a handy way to keep all the loop variables in a convenient location.
each expression inside a for loop is optional. \verb|optional-init-expr| is executed \emph{once} before the loop is entered, the \verb|optional-cond-expr| is a conditional expression which is tested before evaluating the body and the  \verb|optional-post-expr| is evaluated after each time the body is evaluated.

For example, the for loop can be used to loop 10 times in the following way:
\begin{quote}
\begin{verbatim}
for ( int i=0; i<10; i=i+1 ){
    statement;
}
\end{verbatim}\end{quote}

Note that the value of an empty \verb|optional-cond-expr| is taken to be non-zero.

As another example, an infinite loop can be written simply as 
\begin{quote}
\begin{verbatim}
for (;;){
    statement;
}
\end{verbatim}\end{quote}

\subsection{Break Statements}
These are of the form
\begin{quote}
\begin{verbatim}
break;
\end{verbatim}\end{quote}

A break statement can appear only in a looping construct like a for loop, while loop or a do-while loop. When a break statement is encountered, an immediate exit from the innermost exit from the innermost loop containing the statement is effected. Normal execution proceeds with the next statement following the loop. Break statements can be used to exit prematurely from a loop 

\subsection{Continue Statements}
These are of the form 
\begin{quote}
\begin{verbatim}
continue;
\end{verbatim}\end{quote}

These statements can appear wherever a break statement can appear. It only affects the innermost loop which contains the statement. The effect of the continue statement is that the current iteration of the loop is terminated and control proceeds to the next iteration. It is as the body of the loop has finished executing for this iteration.

\subsection{Return Statements}
This is of the form 
\begin{quote}
\begin{verbatim}
return;
return expression;
\end{verbatim}\end{quote}

Return statements are used to return a value back to the calling function.
A return statement is optional for a function. If none is provided, control automatically returns to the calling function after the last statement in the function is executed.

 The \verb|return;| statement causes control to return immediately to the calling function. 

the \verb|return expression;| evaluates the expression and returns the result to the calling function

\subsection{Null Statements}

These are of the form

\begin{quote}
\begin{verbatim}
;
\end{verbatim}\end{quote}

It is primarily used to provide an empty statement in looping constructs like for loops. It can be used in any place which expects a statement.

\section{Future Work}
\label{sec:future_work}

\subsection{List Manipulation}

The list type currently only supports assignment, concatenation and accessing
the elements. Ideally, simple operations such as removing elements, getting
subsequences (possibly using the Python slice notation) may be implemented in
the future.

\subsection{Improve Casting}

The initial release of Pigasus will require explicit casting when attempting to
apply operands of incorrect types to operators. Future release could detect the
required types and cast automatically.

Another aspect worth improving is the ability to cast between Pigasus-specific
types. That is, currently it is possible to cast between the general types such
as string, int, etc. as well as file. However, there is no way to cast between
map and list.

\subsection{Boolean Expressions for Wait Statements}

Statements \verb|wait| and \verb|post| currently require an integer identifer,
but future releases would ideally support logical expressions. For example:
\begin{quote}\begin{verbatim}
post (a || (b && c)) {
  ...
}  
\end{verbatim}\end{quote}

\subsection{Key Events}
\label{sec:key_events}

Currently, all remote tasks must be completely scripted. As a result,
interactive binaries (i.e. those that require input from standard-input during
the program's execution) cannot be handled gracefully. Adding the ability to
transmit key-events would allow users to run remote jobs as if they were
physically sitting in front of the machine.

\subsection{Mouse Events}

Similar to Section \ref{sec:key_events}. If mouse events can be automated
along with key events, then it would greatly expand the number of kinds of jobs
that can be automated and distributed.

\subsection{Support File Input/Output}

Pigasus does not currently support file input and output as it is currently
focused on distributing jobs. Ideally, future versions would allow users to
directly manipulate files and data from Pigasus.

\subsection{Alerts For Completed Jobs}

For jobs that have exceedingly long execution times, it may be useful for some
users to be notified when they are complete. Therefore, a feature that would
allow Pigasus to send an alert by email or SMS could be beneficial.

\subsection{Ability to Resume Pigasus Programs}

The Pigasus program needs to be running in order to manage the distributed jobs
and fetch output. However, if the host machine is turned off or the program is
otherwise terminated, it is impossible to resume the task despite the fact that
remote jobs may still run to completion. We hope to eventually implement the
feature where Pigasus programs may be terminated and run at a future time and
resume where they left off.

\newpage
\section*{Appendix}
\addcontentsline{toc}{section}{Appendix}
\appendix
\section{Grammar}
Here is the YACC compatible grammar for Pigasus. It is partly based on the ANSI
C grammar provided by \cite{degener:ansi}.

\begin{verbatim}
%token IDENTIFIER CONSTANT STRING_LITERAL
%token LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
%token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
%token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN
%token XOR_ASSIGN OR_ASSIGN TYPE_NAME

%token LIST MAP JOB FILE LIST STRING PUSH POST WAIT WAITALL LENGTH 
%token LOADCSV TYPEOF PRINT CONNECT
%token MAPS_TO
%token STRING INT FLOAT BOOL

%token IF ELSE WHILE DO FOR CONTINUE BREAK RETURN

%start translation_unit
%%

primary_expression
  : IDENTIFIER
  | CONSTANT
  | STRING_LITERAL
  | STRING_LITERAL '%' cast_expression
  | '(' expression ')'
  ;

postfix_expression
  : primary_expression
  | postfix_expression '[' expression ']'
  | postfix_expression '[' expression MAPS_TO expression']'
  | postfix_expression '(' ')'
  | postfix_expression '(' argument_expression_list ')'
  ;

argument_expression_list
  : assignment_expression
  | argument_expression_list ',' assignment_expression
  ;

unary_expression
  : postfix_expression
  | unary_operator cast_expression
  | LOADCSV cast_expression
  | TYPEOF cast_expression
  | LENGTH cast_expression
  | PRINT cast_expression
  | CONNECT cast_expression
  | system_expression
  ;

system_expression
  : '@' '{' expression '}'
  ;

unary_operator
  | '+'
  | '-'
  | '!'
  ;

cast_expression
  : unary_expression
  | '(' type_specifier ')' cast_expression
  ;

multiplicative_expression
  : cast_expression
  | multiplicative_expression '*' cast_expression
  | multiplicative_expression '/' cast_expression
  | multiplicative_expression '%' cast_expression
  ;

additive_expression
  : multiplicative_expression
  | additive_expression '+' multiplicative_expression
  | additive_expression '-' multiplicative_expression
  ;


relational_expression
  : relational_expression '<' additive_expression
  | relational_expression '>' additive_expression
  | relational_expression LE_OP additive_expression
  | relational_expression GE_OP additive_expression
  ;

equality_expression
  : relational_expression
  | equality_expression EQ_OP relational_expression
  | equality_expression NE_OP relational_expression
  ;

logical_and_expression
  : inclusive_or_expression
  | logical_and_expression AND_OP inclusive_or_expression
  ;

logical_or_expression
  : logical_and_expression
  | logical_or_expression OR_OP logical_and_expression
  ;

assignment_expression
  : unary_expression assignment_operator assignment_expression
  | additive_expression
  | logical_or_expression
  ;

assignment_operator
  : '='
  ;

expression
  : assignment_expression
  | expression ',' assignment_expression
  ;

declaration
  : type_specifier init_declarator_list ';'
  ;

init_declarator_list
  : init_declarator
  | init_declarator_list ',' init_declarator
  ;

init_declarator
  : declarator
  | declarator '=' initializer
  ;

type_specifier
  : VOID
  | INT
  | FLOAT
  | STRING
  | LIST
  | MAP
  | FILE
  | BOOL
  ;

declarator
  : direct_declarator
  ;

direct_declarator
  : IDENTIFIER
  | '(' declarator ')'
  | direct_declarator '(' parameter_list ')'
  | direct_declarator '(' identifier_list ')'
  | direct_declarator '(' ')'
  ;


parameter_list
  : parameter_declaration
  | parameter_list ',' parameter_declaration
  ;

parameter_declaration
  : type_specifier declarator
  ;

identifier_list
  : IDENTIFIER
  | identifier_list ',' IDENTIFIER
  ;

initializer
  : assignment_expression
  | '[' initializer_list ']'
  | '[' initializer_list ',' ']'
  ;

initializer_list
  : initializer
  | initializer_list ',' initializer
  ;

statement
  : compound_statement
  | expression_statement
  | selection_statement
  | iteration_statement
  | jump_statement
  | push_statement
  | post_statement
  | wait_statement
  | pigasus_statement
  | declaration_list
  ;

compound_statement
  : '{' '}'
  | '{' statement_list '}'
  | '{' declaration_list '}'
  | '{' declaration_list statement_list '}'
  ;

declaration_list
  : declaration
  | declaration_list declaration
  ;

statement_list
  : statement
  | statement_list statement
  ;

expression_statement
  : ';'
  | expression ';'
  ;

init_expression_statement
  : ;
  | expression ';'
  | declaration_list

selection_statement
  : IF '(' expression ')' statement
  | IF '(' expression ')' statement ELSE statement
  ;

iteration_statement
  : WHILE '(' expression ')' statement
  | DO statement WHILE '(' expression ')' ';'
  | FOR '(' init_expression_statement expression_statement ')'
            statement
  | FOR '(' init_expression_statement expression_statement expression ')'
            statement
  ;

jump_statement
  : CONTINUE ';'
  | BREAK ';'
  | RETURN ';'
  | RETURN expression ';'
  ;

push_statement
  : PUSH expression ',' expression ',' expression ',' expression
  ;

post_statement
  : POST IDENTIFIER compound_statement
  | POSTALL compound_statement
  ;

wait_statement
  : WAIT IDENTIFIER
  | WAITALL
  ;

translation_unit
  | function_definition
  | job_definition
  ;

function_definition
  : type_specifier declarator declaration_list compound_statement
  | type_specifier declarator compound_statement
  | declarator declaration_list compound_statement
  | declarator compound_statement
  ;

job_definition
  : JOB IDENTIFIER '(' parameter_declaration ')' compound_statement
  ;
\end{verbatim}

\newpage
\bibliographystyle{abbrv}
\bibliography{lrm}

\end{document}
